﻿/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：ContactsTypeList.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：通讯录类别的查询
 * 作者：侯建
 * 创建日期：2011.04.08
************************************************/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.Module.Default.model;
using Jxym.DBUtility;
using Newtonsoft.Json;

namespace Jxym.wlkc2011.Module.Default.server.Contacts
{
    public partial class ContactsTypeList : System.Web.UI.Page
    {
        string str = "";
        MsSqlDal<model.ContactsType> icc = new MsSqlDal<model.ContactsType>();
        //MsSqlDal<ContactsType> icc = new MsSqlDal<ContactsType>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["ContacType"] != null)
                {
                    int depmetId = Convert.ToInt32(Request.Params["ContacType"]);
                    MsSqlDal<model.ContactsType> iD = new MsSqlDal<model.ContactsType>();
                    //MsSqlDal<ContactsType> iD = new MsSqlDal<ContactsType>();
                    ContactsType dInfo = iD.GetModel("ContactsTypeID=" + depmetId, null);
                    if (dInfo != null)
                    {
                        str = JsonConvert.SerializeObject(dInfo);
                    }
                    Response.Write(str);
                }
                else 
                {
                    IList<ContactsType> icclist = icc.GetList("AddUser = " + Jxym.Common.Request.AdminID("user"), null, "", 0);
                    if (icclist.Count > 0) 
                    {
                        str = "[";
                        foreach (ContactsType c in icclist)
                        {
                            str += "{'id':" + c.ContactsTypeID + ",'text':'" + c.ContactsTypeName + "','leaf':true},";
                        }
                        str = str.TrimEnd(',');
                        str += "]";
                        Response.Write(str);
                    }
                }
            }
        }
    }
}